
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:myapp/common_ui/common_style.dart';
import 'package:myapp/pages/auth/auth_vm.dart';
import 'package:myapp/route/route_utils.dart';
import 'package:oktoast/oktoast.dart';
import 'package:provider/provider.dart';

class RegisterPage extends StatefulWidget{
  const RegisterPage({super.key});


  @override
  State createState() {
    return _RegisterPageState();
  }
}

class _RegisterPageState extends State<RegisterPage>{
  AuthViewModel viewModel = AuthViewModel();


  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(create: (context){
      return viewModel;
    },child: Scaffold(
      backgroundColor: Colors.teal,
      body: Container(
        padding: EdgeInsets.only(left: 20.w,right: 20.w),
        alignment: Alignment.center,
        child: Consumer<AuthViewModel>(builder: (context,vm,child){
          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              commonInput(labelText: "输入账号",onChanged: (value){
                viewModel.registerInfo.name = value;
              }),
              SizedBox(height: 20.h),
              commonInput(labelText: "输入密码",obscureText:true,onChanged: (value){
                viewModel.registerInfo.password = value;
              }),
              SizedBox(height: 20.h),
              commonInput(labelText: "再次输入密码",obscureText:true,onChanged: (value){
                viewModel.registerInfo.rePassword = value;
              }),
              SizedBox(height: 50.h),
              whiteBorderButton(title: "点击注册",onTap: (){
                //点击注册逻辑
                viewModel.register().then((value){
                  if(value == true){
                    showToast("注册成功");
                    RouteUtils.pop(context);
                  }
                });
              }),
            ],
          );
        }),
      ),
    ));
  }

  Widget registerButton(GestureTapCallback? onTap){
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        width: 100.w,
        height: 45.h,
        child: Text("注册",style: TextStyle(color: Colors.white,fontSize: 13.sp),),
      ),
    );
  }
}